package th;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/24 10:08
 * @description 线程睡眠
 */
public class ThreadSleep {

    public static void main(String[] args) {
//        try {
//            down();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        Date date = new Date(System.currentTimeMillis());

        // 模拟系统当前运行时间
        while (true) {
            try {
                Thread.sleep(1000);
                System.out.println("模拟系统当前运行时间 = " + new SimpleDateFormat("HH:mm:ss").format(date));
                date = new Date(System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 摸您倒计时
     *
     * @throws InterruptedException
     */
    private static void down() throws InterruptedException {
        int num = 10;
        while (true) {
            Thread.sleep(1000);
            System.out.println(num--);
            if (num <= 0) {
                break;
            }
        }
    }
}
